package com.example.service.articleImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.childer_articles;
import com.example.mapper.article.articlesQuery;
import com.example.service.article.articlesService;
import org.apache.ibatis.annotations.Param;
import org.apache.logging.log4j.util.Strings;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
@Configuration
public class articlesServiceImpl extends ServiceImpl<articlesQuery, childer_articles> implements articlesService {

    @Resource
    private articlesQuery articlesQuery;

    @Override
    public List<childer_articles> findBycategory(int category) {
        return articlesQuery.findBycategoey(category);
    }

    @Override
    public List<childer_articles> findByname(String name,int a,int b) {
        return articlesQuery.findByName(name,a,b);
    }

    @Override
    public List<childer_articles> findByname(String name) {
        return articlesQuery.findByName(name);
    }

    @Override
    public IPage<childer_articles> getPage(int currentPage, int pageSize, childer_articles articles) {
        System.out.println("aaa");
        System.out.println(currentPage);
        System.out.println(pageSize);
        LambdaQueryWrapper<childer_articles> lqw = new LambdaQueryWrapper<childer_articles>();
        lqw.like(Strings.isNotEmpty(articles.getTitle()),childer_articles::getTitle,articles.getTitle());
        lqw.eq(childer_articles::getFit,articles.getFit());
        IPage page = new Page(currentPage,pageSize);
        articlesQuery.selectPage(page,lqw);
        return page;
    }

    @Override
    public IPage<childer_articles> getPagebyname(int currentPage, int pageSize, childer_articles articles) {
        System.out.println("aaa");
        System.out.println(currentPage);
        System.out.println(pageSize);
        LambdaQueryWrapper<childer_articles> lqw = new LambdaQueryWrapper<childer_articles>();
        lqw.like(Strings.isNotEmpty(articles.getTitle()),childer_articles::getTitle,articles.getTitle());
//        lqw.eq(childer_articles::getFit,articles.getFit());
        IPage page = new Page(currentPage,pageSize);
        articlesQuery.selectPage(page,lqw);
        return page;
    }

    @Override
    public List<childer_articles> selectTop() {
        return articlesQuery.select();
    }

    @Override
    public List<childer_articles> selectbyid(int id) {
        return articlesQuery.selectbyid(id);
    }

    @Override
    public List<childer_articles> selectbyuserid(String userid) {
        return articlesQuery.selectbyuserid(userid);
    }

    @Override
    public List<childer_articles> selectall(Integer a, Integer b) {
        return articlesQuery.selectall(a,b);
    }

    @Override
    public int allnumber() {
        return articlesQuery.allnumber();
    }

    @Override
    public boolean deletebyid(int id) {
        return articlesQuery.deleteById(id)>0;
    }

    @Override
    public boolean insert(childer_articles childer_articles) {
        return articlesQuery.insert(childer_articles)>0;
    }
}
